package com.bsoft.gol.hcs.specialist.controller;

import com.bsoft.gol.hcs.clinical.bean.req.QueryInspectionItemListReq;
import com.bsoft.gol.hcs.clinical.bean.response.QueryInspectionItemListResp;
import hcn.util.BaseResponse;
import hcn.util.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bsoft.gol.hcs.specialist.bean.request.ListIndexRequest;
import com.bsoft.gol.hcs.specialist.bean.response.ListSampleTypeResponse;
import com.bsoft.gol.hcs.specialist.bean.vo.IndexListVo;
import com.bsoft.gol.hcs.specialist.service.IExamineService;
import com.bsoft.gol.hcs.specialist.service.ILisInspectionIndexService;
import com.bsoft.gol.hcs.utils.CommonUtils;

import java.util.List;

/**
 * @Description: 检验接口
 * @Author: xhf
 * @Date: 2020/6/2 15:22
 **/
@Controller
@RequestMapping(value = "/api/auth/medicalSkills")
public class ExamineController {
    private static final Logger log = LoggerFactory.getLogger(ExamineController.class);
    @Autowired
    private IExamineService specialistExamineService;
    @Autowired
    private ILisInspectionIndexService lisInspectionIndexService;

    /**
     * @Description: 获取检验单项目列表
     * @Author: xhf
     * @Date: 2020/6/2 15:24
     **/
    @RequestMapping(value = "/queryInspectionItemList", method = RequestMethod.POST)
    @ResponseBody
    public BaseResponse<List<QueryInspectionItemListResp>> queryInspectionItemList(@RequestBody QueryInspectionItemListReq request) {
        log.info("MedicalExamineController.queryInspectionItemList入参：{}", request);
        BaseResponse<List<QueryInspectionItemListResp>> baseResponse = new BaseResponse<>();
        if(CommonUtils.isEmpty(request.getDepartmentId())){
            request.setDepartmentId(null);
        }
        if(CommonUtils.isEmpty(request.getDoctorId())){
            request.setDoctorId(null);
        }
        try {
            List<QueryInspectionItemListResp> listBaseResponse = specialistExamineService.queryInspectionItemList(request);
            baseResponse.setData(listBaseResponse);
        } catch (Exception e) {
            log.error("查询检验单项目列表失败");
            baseResponse.setCode(ResultCode.ERROR);
            baseResponse.setMessage("查询检验单项目列表失败");
        }

        log.info("MedicalExamineController.queryInspectionItemList出参：{}", baseResponse);
        return baseResponse;
    }


    @RequestMapping(value = "/querySampleType", method = RequestMethod.POST)
    @ResponseBody
    public BaseResponse<List<ListSampleTypeResponse>> querySampleType(@RequestBody ListIndexRequest request) {
        log.info("MedicalExamineController.querySampleType入参：{}", request);
        BaseResponse<List<ListSampleTypeResponse>> baseResponse = new BaseResponse<>();

        try {
            List<ListSampleTypeResponse> listBaseResponse = lisInspectionIndexService.listSampleType(request);
            baseResponse.setData(listBaseResponse);
        } catch (Exception e) {
            log.error("查询检验样本类型列表失败");
            baseResponse.setCode(ResultCode.ERROR);
            baseResponse.setMessage("查询检验单项目列表失败");
        }

        log.info("MedicalExamineController.queryInspectionItemList出参：{}", baseResponse);
        return baseResponse;
    }

    @RequestMapping(value = "/listIndex", method = RequestMethod.POST)
    @ResponseBody
    public BaseResponse<List<IndexListVo>> listIndex(@RequestBody ListIndexRequest request) {
        log.info("MedicalExamineController.queryInspectionItemList入参：{}", request);
        BaseResponse<List<IndexListVo>> baseResponse = new BaseResponse<>();

        try {
            List<IndexListVo> listBaseResponse = lisInspectionIndexService.queryListIndexList(request);
            baseResponse.setData(listBaseResponse);
        } catch (Exception e) {
            log.error("查询检验单项目列表失败");
            baseResponse.setCode(ResultCode.ERROR);
            baseResponse.setMessage("查询检验单项目列表失败");
        }

        log.info("MedicalExamineController.queryInspectionItemList出参：{}", baseResponse);
        return baseResponse;
    }

}
